import ResultWrapper = require('../ResultWrapper')
import RequestResult = require("../RequestResult")
import RequestListResult = require("../RequestListResult")
import BaseModel = require('../BaseModel')
import Product = require('../model/Product')
//code1

//code1

/**
 * 库存产品列表/搜索
 */
class StockApiList {
    
    get path(): string {
        return '/StockApi/list'
    }
    
    get isUpload(): boolean {
        return false
    }

    setup(app: any, path: string) {
        console.log('setup service: /' + path)
    }

    //GET
    find(params: any, callback: Function) {
        return this.doWork(params.query)
    }

    doWork(params: any): Promise<any> {

        let page = params.page
        let page_size = params.page_size || RequestListResult.PAGE_SIZE
        /**产品分类id*/
        let category_id: number = params.category_id
        /**通过关键字/编号/编码搜索*/
        let by_keyword: string = params.by_keyword
        /**通过拼音首字母*/
        let by_letter: string = params.by_letter
        /**顾客角色：0.普通散客[默认]，1.批发商顾客*/
        let buyer_role: number = params.buyer_role
        /**通过ids字符串筛选产品列表，以逗号分隔，如: 1,2,3*/
        let ids: string = params.ids
        /**是否分页（0.不分页，1.分页）*/
        let is_paginate: number = params.is_paginate


        let callback = (
            resolve: (data: RequestListResult<Product>) => void, 
            reject: (error: Error) => void) => {

            let data = new Product()
            let result = ResultWrapper.wrapList([data])
            result.page = page
            result.page_size = page_size
            result.total_count = 3 * page_size + page_size/2
            result.message = '假数据'

//code2

//code2
            resolve(result)
        }
        return new Promise(callback)
    }
}

export = StockApiList